import java.net.*;
import java.io.*;

public class FileServer {
  public static void main (String [] args ) throws IOException {
	  
    // create socket
    ServerSocket servsock = new ServerSocket(13267);
    while (true) {
      System.out.println("Waiting...");

      Socket sock = servsock.accept();
      System.out.println("Accepted connection : " + sock);
      
      long start = System.currentTimeMillis();
      
      
      // receive file
      ObjectInputStream ois = new ObjectInputStream(sock.getInputStream());
      FileOutputStream fos = new FileOutputStream ("output.tmp"); //("output"+(files)+".mp3");
      BufferedOutputStream bos = new BufferedOutputStream(fos);
      data myDataObject = new data(new byte[1]);
  	try
  	{
  		myDataObject = (data)ois.readObject();
  	}
  	catch (ClassNotFoundException e)
  	{
  		// TODO Auto-generated catch block
  		e.printStackTrace();
  	}

      byte [] mybytearray  = myDataObject.mybytes;

      bos.write(mybytearray, 0 ,mybytearray.length);
      bos.flush();
      long end = System.currentTimeMillis();
      System.out.println("The transfer took: " + (end-start) + " msec");
      
      bos.close();
      sock.close();
      }
    }
  }
